function RunMenu()
{
    var choice = 0;
    
    while(true)
    {
    	choice = GetChoice();
    	
    	if (choice != 0)
    	{
    		RunChoice(choice);
    	}
    	else
    	{
    		break;
    	}
    }
}

// Execute the application the user choose.
function RunChoice(a_choice)
{
	if (a_choice == 1)
	{
		FahrenheitToCelcius();
	}
	else if (a_choice == 2)
	{
		CelciustoFahrenheit();
	}
	else if (a_choice == 3)
	{
		InitGame();
	}
}

// Get and return the users choice.
function GetChoice()
{
	
	var userChoice = prompt("0. Exit\n" + 
	   				"\n" +
				    "1. Fahrenheit to Celsius\n" +
				    "2. Celcius to Fahrenheit\n" +
				    "3. Guess number");
	
	return userChoice;
}

// Convert the fahrenheit input by the user to celcius.
function FahrenheitToCelcius()
{
	// Ask the user for a number for as long as the user doesn't input a number.
	do
	{
		var fahrenheit = prompt("Fahrenheit?");
	}
	while(isNaN(fahrenheit) == true)
	
	// Convert the fahrenheit to celcius.
	var celcius = (5/9)*(fahrenheit-32);
	
	// Give the result to the user.
	alert(fahrenheit + " degrees fahrenheit equals " + celcius + " degrees celcius.");
}

// Convert the celcius input by the user to fahrenheit.
function CelciustoFahrenheit()
{
	// Ask the user for a number for as long as the user doesn't input a number.
	do
	{
		var celcius = prompt("Celcius?");
	}
	while(isNaN(celcius) == true)
	
	// Convert the celcius to fahrenheit.
	var fahrenheit = (9/5)*celcius+32;
	
	// Give the result to the user.
	alert(celcius + " degrees celcius equals " + fahrenheit + " degrees fahrenheit.");
}